package com.jf.identity.holder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author FCG
 */
@Component
public class DataSourceKeyHolder {
    private volatile ThreadLocal<String> dataSourceKey = new ThreadLocal<>();
    private final Logger logger = LoggerFactory.getLogger(getClass());
    public void setDataSourceKey(String key) {
//        logger.debug("设置数据源:{}",key);
        dataSourceKey.set(key);
    }

    public String getDataSourceKey() {
        String key = dataSourceKey.get();
//        logger.debug("获得数据源:{}",key);
        return key;
    }

    public void remove() {
//        logger.debug("清除数据源");
        dataSourceKey.remove();
    }
}
